package cn.chenc.framework.demo.config;

import cn.chenc.framework.jpa.support.BaseJpaRepositoryFactoryBean;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * 　@description: TODO
 * 　@author secret
 * 　@date 2021/7/21 20:47
 *
 */
@Configuration
@EnableJpaRepositories(
        // 设置Repository所在位置
        basePackages = { "cn.chenc.framework.demo.dao" },
        // 覆盖SpringBoot提供的默认配置
        repositoryFactoryBeanClass = BaseJpaRepositoryFactoryBean.class)
public class DemoSourceConfig {


    /**
     * 向spring容器暴露组合数据源JdbcTemplate
     * @param dataSource
     * @return
     * @author secret
     */
    @Bean(name = "multipleDataJdbcTemplate")
    public JdbcTemplate primaryJdbcTemplate(DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
}
